package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.dto.DishDto;
import com.itheima.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dish")
public class DishController {


    @Autowired
    private DishService dishService;

    @PostMapping
    public R save(@RequestBody DishDto dishDto) {
        R r = dishService.saveWithFlavor(dishDto);
        return r;
    }

    @GetMapping("/page")
    public R page(Integer page, Integer pageSize, String name) {
        R r = dishService.findPage(page, pageSize, name);
        return r;
    }

    @GetMapping("/{id}")
    public R findById(@PathVariable Long id) {
        R r = dishService.findById(id);
        return r;
    }

    @PutMapping
    public R updateByDishId(@RequestBody DishDto dishDto) {
        R r = dishService.updateByDishId(dishDto);
        return r;
    }

    //  瑞吉外卖  1.批量删除
    @DeleteMapping
    public R delete(Long[] ids) {
        R r = dishService.delete(ids);
        return r;
    }

    //  2.批量启售
    @PostMapping("/status/{id}")
    public R status(Long[] ids, @PathVariable Integer id) {
        R r = dishService.status(id, ids);
        return r;
    }

    @GetMapping("/list")
    public R list(Long categoryId) {
        return dishService.findAll(categoryId);
    }


}
